/**
 * Copyright 2012 Roger Cockshutt
 * krakenbrau@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.parallelrl.util;

import java.util.HashMap;
import java.util.List;

/**
 * @author Roger Cockshutt
 *
 */
public class Space2D implements ISpace2D {
	
	private Tree2D spaceTree;
	private Box2D boundingBox;
	private HashMap<Long, Long> entityPositionMap;

	/**
	 * 
	 */
	public Space2D(Box2D bounds) {
		boundingBox = bounds;
		spaceTree = new Tree2D(boundingBox);
		entityPositionMap = new HashMap<Long, Long>();
	}
	
	public List<Long> getEntitiesIn(Box2D range) {
		
	}

	/* (non-Javadoc)
	 * @see com.googlecode.parallelrl.util.ISpace2D#getSubSpace(com.googlecode.parallelrl.util.Box2D)
	 */
	@Override
	public ISpace2D getSubSpace(Box2D range) {
		for (int y = range.center.y - range.halfDimension.y; y < range.center.y + range.halfDimension.y; y++) {
			for (int x = range.center.x - range.halfDimension.x; x < range.center.x + range.halfDimension.x; x++) {
				if (!boundingBox.containsPoint(new Point2D(y, x))) {
					return null;
				}
			}
		}
		return new Space2D(range);
	}

	/* (non-Javadoc)
	 * @see com.googlecode.parallelrl.util.ISpace2D#getBounds()
	 */
	@Override
	public Box2D getBounds() {
		return boundingBox;
	}

	/* (non-Javadoc)
	 * @see com.googlecode.parallelrl.util.ISpace2D#getPointsIn(com.googlecode.parallelrl.util.Box2D)
	 */
	@Override
	public List<Point2D> getPointsIn(Box2D range) {
		return spaceTree.queryRange(range);
	}

	/* (non-Javadoc)
	 * @see com.googlecode.parallelrl.util.ISpace2D#getAllPoints()
	 */
	@Override
	public List<Point2D> getAllPoints() {
		return spaceTree.queryRange(boundingBox);
	}

}
